from airtest.core.api import *
from poco.drivers.unity3d import UnityPoco

from config import BaseDir


class App:
    poco = None
    is_poco = True

    @classmethod
    def init_device(cls):
        # 初始化设备
        init_device(platform='Android', uuid="882QADT8SJD48")
        # init_device(platform='Android', uuid="emulator-5554")
        # connect_device("android:///"
        # 连接设备
        print("------开始连接设备------")
        connect_device("android:///")
        # 启动app
        print("------启动app------")
        start_app("com.pantheon.monarch", 'MainActivity')
        # 点击无版本更新
        touch(Template(BaseDir + r"\icon\img.png"))
        time.sleep(4)

    @classmethod
    def start(cls):
        if cls.poco is None:
            cls.poco = UnityPoco()
            print("------------start-------------poco是个啥：", cls.poco)
        return cls.poco

    @classmethod
    def quit(cls):
        if cls.poco is not None and cls.is_poco:
            sleep(5)
            print("-----关闭app-----")
            print("------poco是个啥：", cls.poco)
            stop_app("com.pantheon.monarch")
            print("关闭后----poco是个啥：", cls.poco)
            cls.poco = None
